(function($) {
    $.fn.touchWipe = function(e) {
        var f = {
            itemDelete: '.item-delete',
        };
        var g = $.extend({}, f, e);
        var h = $(g.itemDelete).width();
        var i;
        var j;
        var k;
        var m;
        var X = 0;
        var Y = 0;
        var n = 0;
        var o = 0;
        $('.layim-list-history').on('touchstart', '.layim-list-history>li', function(c) {
            var d = this;
            i = c.targetTouches[0].pageX;
            j = c.targetTouches[0].pageY;
            o = d.style.WebkitTransform.replace(/translateX\(/g, '').replace(/px\)/g, '') * 1;
            if (o == 0) {
                $('.layim-list-history').on('touchmove', '.layim-list-history>li', function(a) {
                    h = $(g.itemDelete).width();
                    if (n == 0) {
                        setScrollX(a);
                        return;
                    } else if (n == 1) {
                        a.preventDefault();
                    } else {
                        return;
                    }
                    var b = this;
                    k = a.targetTouches[0].pageX;
                    X = k - i;
                    if (X >= 0) {
                        $(this).attr('layim-event', 'chat');
                        b.style.WebkitTransform = 'translateX(' + 0 + 'px)';
                    } else if (X < 0) {
                        var l = Math.abs(X);
                        if (l > 40) {
                            $(this).attr('layim-event', '');
                        }
                        b.style.WebkitTransform = 'translateX(' + -l + 'px)';
                        if (l > h) {
                            l = h;
                            b.style.WebkitTransform = 'translateX(' + -l + 'px)';
                        }
                    }
                });
            } else if (o < 0) {
                $('.layim-list-history').on('touchmove', '.layim-list-history>li', function(a) {
                    if (n == 0) {
                        setScrollX(a);
                        return;
                    } else if (n == 1) {
                        a.preventDefault();
                    } else {
                        return;
                    }
                    var b = this;
                    k = a.targetTouches[0].pageX;
                    X = k - i;
                    if (X >= 0) {
                        var r = -h + Math.abs(X);
                        b.style.WebkitTransform = 'translateX(' + r + 'px)';
                        if (r > 0) {
                            r = 0;
                            b.style.WebkitTransform = 'translateX(' + r + 'px)';
                        }
                    } else {
                        b.style.WebkitTransform = 'translateX(' + -h + 'px)';
                    }
                });
            }
        });
        $('.layim-list-history').on('touchend', '.layim-list-history>li', function(a) {
            var b = this;
            o = b.style.WebkitTransform.replace(/translateX\(/g, '').replace(/px\)/g, '') * 1;
            if (o > -h / 2) {
                b.style.transition = 'all 0.2s';
                b.style.WebkitTransform = 'translateX(' + 0 + 'px)';
                b.style.transition = 'all 0';
                o = 0;
            } else {
                b.style.transition = 'all 0.2s';
                b.style.WebkitTransform = 'translateX(' + -h + 'px)';
                b.style.transition = 'all 0';
                o = -h;
            }
            n = 0;
        });

        function setScrollX(a) {
            k = a.targetTouches[0].pageX;
            m = a.targetTouches[0].pageY;
            X = k - i;
            Y = m - j;
            if (Math.abs(X) > Math.abs(Y)) {
                n = 1;
            } else {
                n = 2;
            }
            return n;
        }
        return this;
    };
})(Zepto);
